<!-- 厂家-送达-设备接收确认 -->
<template>
	<Card>
		<template #head>
			设备接收确认
		</template>
		<template #body>
			<CellField v-model="formData.user" :label="UserLabel"></CellField>
			<CellField v-model="formData.phone" type="number" :label="PhoneLabel"></CellField>
			<CellItem v-model="formData.situation" dicKey="repair_result" label="维修情况"></CellItem>
			<CellItem v-model="formData.appearance" dicKey="repair_equipment_status" label="设备状态外观"></CellItem>
			<CellItem v-model="formData.state" dicKey="repair_equipment_data" label="设备数据状态"></CellItem>

			<!-- 厂家放弃报价 -->
			<template v-if="Hidden_3_5_6">
				<template v-if="Hidden_4">
					<CellItem v-model="formData.test" :customActionSheetList="customActionSheetList" label="测试报告"></CellItem>
				</template>
				<CellItem v-model="formData.voiceReturn" :customActionSheetList="customActionSheetList" label="发票返回"></CellItem>
				<CellItem v-model="formData.voiceType" :disabled="Disabled" dicKey="Invoice_type" label="发票类型"></CellItem>
				<CellField v-model="formData.voiceNo" :disabled="Disabled" label="发票号" required></CellField>
				<template v-if="where =='factory'">
					<CellItem v-model="formData.settlementMethod" dicKey="settlement_method" label="结算方式"></CellItem>

				</template>
			</template>


		</template>
	</Card>
</template>

<script>
	import Card from '@/components/card/components/cardBaseWrapper.vue'
	import { factoryState } from '@/sendRepair/factory/state.js'
	export default {
		components: {
			Card,
		},
		props: {
			where: {
				type: String,
				default: 'factory'
			},
			// （1.已修好 2.未修好 3.厂家无法维修，4.科室放弃维修，5.厂家放弃报价，6.报价审核不通过）
			source: {
				type: [String, Number],
				default: ''
			},
			defaultData: {
				type: Object,
				default: () => {
					return {}
				}
			},


		},

		computed: {

			UserLabel() {
				return this.where != 'factory' ? '实际取走人' : '接收人'
			},
			PhoneLabel() {
				return this.where != 'factory' ? '取走人电话' : '接收人电话'
			},
			// 厂家无法维修、厂家放弃报价、报价审核不通过
			Hidden_3_5_6() {
				if (this.where != 'factory') {
					return true
				}
				return ![3, 5, 6].includes(Number(this.source || 0));
			},
			// 科室放弃维修
			Hidden_4() {
				if (this.where != 'factory') {
					return true
				}
				return ![4].includes(Number(this.source || 0));
			},
			// 报价审核不通过 、厂家放弃报价
			Source_5_6() {
				let { FactoryGiveUpQuote, QuoteReviewNot } = factoryState.CardSourceState
				return [FactoryGiveUpQuote, QuoteReviewNot].includes(Number(this.source || 0))
			},

			// 设备数据
			DeviceData() {
				let { finishRepairResultVo } = this?.defaultData || {}
				return finishRepairResultVo || {}
			},
			// 送回处置数据
			ReturnDisposal() {

				let { deptReclaim } = this?.defaultData || {}
				return deptReclaim || {}
			},

			UserPhone() {
				console.log(this.defaultData, 'defaultDatas');
				if (this.where != 'factory') {

					let { takeAwayInfoVo } = this?.defaultData || {}
					return {
						user: takeAwayInfoVo?.receiveUserToName || '',
						phone: takeAwayInfoVo?.receivePhone || ''
					}
				} else {
					let { sendDeptResultVo } = this?.defaultData || {}
					return {
						user: sendDeptResultVo?.receiveUser || '',
						phone: sendDeptResultVo?.receivePhone || ''
					}
				}
			},
			Disabled() {
				return this.formData.voiceReturn == 0
			}

		},
		data() {
			return {
				customActionSheetList: [{
					name: '是',
					value: 1
				}, {
					name: '否',
					value: 0
				}],
				formData: {
					user: '',
					phone: '',
					situation: 1,
					appearance: 1,
					state: '',
					test: '',
					voiceReturn: '',
					voiceType: "",
					voiceNo: '',
					settlementMethod: ''
				}

			}
		},
		watch: {

			DeviceData: {
				deep: true,
				handler: function(val) {
					console.log(val, '-----watch-----');
					this.initDefaultData()
				}
			}
		},
		mounted() {
			this.$nextTick(() => {
				// this.formData.situation = this.source

			})
			// this.initDefaultData()
		},
		methods: {
			initDefaultData() {
				this.formData = {
					user: this.UserPhone.user,
					phone: this.UserPhone.phone,
					situation: this.Source_5_6 ? this.source : this.DeviceData.repairResult || 1,
					appearance: this.DeviceData.deviceState != null ? this.DeviceData.deviceState : 1,
					state: this.DeviceData.deviceData != null ? this.DeviceData.deviceData : 1,
					test: this.DeviceData.testReportFlag != null ? this.DeviceData.testReportFlag : 0,
					voiceReturn: this.DeviceData.invoiceFlag,
					voiceType: this.DeviceData.invoiceType || '',
					voiceNo: this.DeviceData.invoiceNum || '',
					settlementMethod: this.DeviceData?.settlementMethod || 1
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.label {
		&-value {
			display: block;
			font-weight: 400;
			font-size: 28rpx;
			color: #409EFF;
			text-align: right;
		}

		&-content {
			text-align: right;
		}
	}

	.attachment {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
</style>
